import 'package:flutter/material.dart';

// 本地化
class LocaleProvider with ChangeNotifier {
  static const localeValueList = ['en', 'zh-CN'];

  int _localeIndex = 0;

  int get localeIndex => _localeIndex;

  LocaleProvider();

  Locale? get locale {
    if (_localeIndex >= 0) {
      var value = localeValueList[_localeIndex].split("-");
      return Locale(value[0], value[1]);
    }
    // 跟随系统
    return null;
  }

  switchLocale(int index) {
    _localeIndex = index;
    notifyListeners();
  }
}
